#include "Class.h"
#include"Student.h"
#include <string>
#include <vector>
#include<algorithm>
using namespace std;
Class::Class(){
	classNumber = "";
	password = "999999";
}


Class::Class(string classNumber,string password) {
	this->classNumber = classNumber;
	this->password = password;
}

void Class::addStudent(string studentNumber, string name, string gender, int courseSum, string CourseName[], int CourseGrade[], string password) {
	Student a = Student(studentNumber, name, gender, courseSum, CourseName, CourseGrade, password);
	students.push_back(a);
	sort(students.begin(), students.end(), [](Student& a, Student& b) {
		return a.getGradeSum() < b.getGradeSum();
		});
	Class::setRank();
}


void Class::setRank() {
	for (int i = 0; i < students.size(); i++) {
		students[i].setClassRank(i + 1);
	}
}


bool Class::deleteStudent(string studentNumber) {
	for (int i = 0; i < students.size(); i++) {
		if (students[i].getStudentNumber() == studentNumber) {
			students.erase(students.begin() + i, students.begin() + i + 1);
			return 1;
		}
	}
	return 0;
}


int Class::findstudent(string studentNumber) {
	for (int i = 0; i < students.size(); i++) {
		if (students[i].getStudentNumber() == studentNumber) {
			return i;
		}
	}
	return -1;
}


void Class::printClassGradeRank() {
	for (int i = 0; i < students.size(); i++) {
		students[i].printStudentinformtion();
	}
}


bool Class::changePassword(string oldPasseword, string newPassword) {
	if (oldPasseword != this->password) return 0;
	else this->password = newPassword;
	return 1;
}


string Class::getPassword() {
	return this->password;
}


bool Class::enterPassword(string password) {
	if (password != this->password) return 0;
	else return 1;
}